/**
 * 系统角色
 */
import { IsDefined, IsInt, IsNotEmpty, IsString, Length } from "class-validator";
import { BaseEntity } from "../BaseEntity";
import { TStatus } from "../../types/CommonType";
import { BelongsToManyAddAssociationMixin, BelongsToManyGetAssociationsMixin, Model } from "sequelize";
import { IUserModel } from "./SysUserEntity";
import { IMenuModel } from "./SysMenuEntity";

export default class SysRoleEntity extends BaseEntity {
  public menuIds?: number[];
  public id?: number;

  @Length(2, 20)
  @IsString()
  @IsNotEmpty()
  @IsDefined()
  public roleName: string;

  @Length(2, 20)
  @IsString()
  @IsDefined()
  public roleKey: string;

  @IsInt()
  @IsNotEmpty()
  @IsDefined()
  public roleSort: number;

  @IsString()
  public dataScope: string;

  @IsString()
  public menuCheckStrictly: string;

  @IsString()
  public deptCheckStrictly: string;

  @IsString()
  @IsNotEmpty()
  @IsDefined()
  public status: TStatus;

  @IsString()
  public remark: string;

  public static transform(plainObject: object): SysRoleEntity {
    return super.baseTransform(SysRoleEntity, plainObject);
  }
}

export interface IRoleModel extends Model<SysRoleEntity> {
  getUser: BelongsToManyGetAssociationsMixin<IUserModel>;
  setUser: BelongsToManyGetAssociationsMixin<IUserModel>;
  addMenu: BelongsToManyAddAssociationMixin<IMenuModel, "id">;
  getMenu: BelongsToManyGetAssociationsMixin<IMenuModel>;
  setMenu: BelongsToManyGetAssociationsMixin<IMenuModel>;
}
